package com.mojian.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mojian.mapper.SysZbMapper;
import com.mojian.entity.SysZb;
import com.mojian.service.SysZbService;
import com.mojian.utils.PageUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;

/**
 * 招标 服务实现类
 */
@Service
@RequiredArgsConstructor
public class SysZbServiceImpl extends ServiceImpl<SysZbMapper, SysZb> implements SysZbService {

    @Autowired
    private SysZbMapper sysZbMapper;

    /**
     * 查询招标分页列表
     */
    @Override
    public IPage<SysZb> selectPage(SysZb sysZb) {
        LambdaQueryWrapper<SysZb> wrapper = new LambdaQueryWrapper<>();
        // 构建查询条件
        wrapper.eq(sysZb.getId() != null, SysZb::getId, sysZb.getId());
        wrapper.eq(sysZb.getUserId() != null, SysZb::getUserId, sysZb.getUserId());
        wrapper.eq(sysZb.getZbbt() != null, SysZb::getZbbt, sysZb.getZbbt());
        wrapper.eq(sysZb.getZbwj() != null, SysZb::getZbwj, sysZb.getZbwj());
        wrapper.eq(sysZb.getZbms() != null, SysZb::getZbms, sysZb.getZbms());
        wrapper.eq(sysZb.getStatus() != null, SysZb::getStatus, sysZb.getStatus());
        wrapper.eq(sysZb.getKsrq() != null, SysZb::getKsrq, sysZb.getKsrq());
        wrapper.eq(sysZb.getJsrq() != null, SysZb::getJsrq, sysZb.getJsrq());
        wrapper.eq(sysZb.getCreateTime() != null, SysZb::getCreateTime, sysZb.getCreateTime());
        wrapper.eq(sysZb.getUpdateTime() != null, SysZb::getUpdateTime, sysZb.getUpdateTime());
        wrapper.eq(sysZb.getA1() != null, SysZb::getA1, sysZb.getA1());
        wrapper.eq(sysZb.getA2() != null, SysZb::getA2, sysZb.getA2());
        wrapper.eq(sysZb.getA3() != null, SysZb::getA3, sysZb.getA3());
        wrapper.eq(sysZb.getA4() != null, SysZb::getA4, sysZb.getA4());
        wrapper.eq(sysZb.getA5() != null, SysZb::getA5, sysZb.getA5());
        wrapper.eq(sysZb.getA6() != null, SysZb::getA6, sysZb.getA6());
        wrapper.eq(sysZb.getA7() != null, SysZb::getA7, sysZb.getA7());
        wrapper.eq(sysZb.getA8() != null, SysZb::getA8, sysZb.getA8());
        wrapper.eq(sysZb.getA9() != null, SysZb::getA9, sysZb.getA9());
        wrapper.eq(sysZb.getA10() != null, SysZb::getA10, sysZb.getA10());

        return page(PageUtil.getPage(), wrapper);
    }

    /**
     * 查询招标列表
     */
    @Override
    public List<SysZb> selectList(SysZb sysZb) {
        LambdaQueryWrapper<SysZb> wrapper = new LambdaQueryWrapper<>();
        // 构建查询条件
        wrapper.eq(sysZb.getId() != null, SysZb::getId, sysZb.getId());
        wrapper.eq(sysZb.getUserId() != null, SysZb::getUserId, sysZb.getUserId());
        wrapper.eq(sysZb.getZbbt() != null, SysZb::getZbbt, sysZb.getZbbt());
        wrapper.eq(sysZb.getZbwj() != null, SysZb::getZbwj, sysZb.getZbwj());
        wrapper.eq(sysZb.getZbms() != null, SysZb::getZbms, sysZb.getZbms());
        wrapper.eq(sysZb.getStatus() != null, SysZb::getStatus, sysZb.getStatus());
        wrapper.eq(sysZb.getKsrq() != null, SysZb::getKsrq, sysZb.getKsrq());
        wrapper.eq(sysZb.getJsrq() != null, SysZb::getJsrq, sysZb.getJsrq());
        wrapper.eq(sysZb.getCreateTime() != null, SysZb::getCreateTime, sysZb.getCreateTime());
        wrapper.eq(sysZb.getUpdateTime() != null, SysZb::getUpdateTime, sysZb.getUpdateTime());
        wrapper.eq(sysZb.getA1() != null, SysZb::getA1, sysZb.getA1());
        wrapper.eq(sysZb.getA2() != null, SysZb::getA2, sysZb.getA2());
        wrapper.eq(sysZb.getA3() != null, SysZb::getA3, sysZb.getA3());
        wrapper.eq(sysZb.getA4() != null, SysZb::getA4, sysZb.getA4());
        wrapper.eq(sysZb.getA5() != null, SysZb::getA5, sysZb.getA5());
        wrapper.eq(sysZb.getA6() != null, SysZb::getA6, sysZb.getA6());
        wrapper.eq(sysZb.getA7() != null, SysZb::getA7, sysZb.getA7());
        wrapper.eq(sysZb.getA8() != null, SysZb::getA8, sysZb.getA8());
        wrapper.eq(sysZb.getA9() != null, SysZb::getA9, sysZb.getA9());
        wrapper.eq(sysZb.getA10() != null, SysZb::getA10, sysZb.getA10());
        return list(wrapper);
    }

//    /**
//     * 查询招标中列表
//     */
//    //投标得分排序
//    @Override
//    public List<Map<String, Object>> selectCustomList(String zbid) {
//        return sysZbMapper.selectCustomList(zbid);
//    }

    @Override
    public List<Map<String, Object>> selectZBZList( ) {
        Long userid=StpUtil.getLoginIdAsLong();
        return sysZbMapper.selectZBZList(userid);
    }

    /**
     * 新增招标
     */
    @Override
    public boolean insert(SysZb sysZb) {
        sysZb.setUserId(StpUtil.getLoginIdAsLong());
        return save(sysZb);
    }

    /**
     * 修改招标
     */
    @Override
    public boolean update(SysZb sysZb) {
        return updateById(sysZb);
    }

    @Override
    public boolean updateJh(SysZb sysZb) {
        sysZb.setStatus(1);
        return updateById(sysZb);
    }

    @Override
    public boolean updateQxJh(SysZb sysZb) {
        sysZb.setStatus(0);
        return updateById(sysZb);
    }

    /**
     * 批量删除招标
     */
    @Override
    public boolean deleteByIds(List<Long> ids) {
        return removeByIds(ids);
    }
}
